<?php

namespace common\model;

use think\model\RelationModel;
use teamones\dbeventObserver\interfaces\SplSubject;
use teamones\dbeventObserver\SplSubjectEnforcer;

class TaskWorkOrderModel extends RelationModel implements SplSubject
{
    use SplSubjectEnforcer;

    const STATUS_UNTREATED = 0; // 未处理
    const STATUS_PROCESSED = 1; // 已结单
    const STATUS_EXPIRED = 2; // 已撤销
    const STATUS_PROGRESS = 3; // 处理中

    // deprecated
    const STATUS_DEAL = 4; // - 已不使用 老数据才有

    //未处理的工单状态

    // 未关闭有效工单状态组
    const STATUS_NOT_CLOSED_GROUP = [
        TaskWorkOrderModel::STATUS_UNTREATED,
        TaskWorkOrderModel::STATUS_PROGRESS,
        TaskWorkOrderModel::STATUS_DEAL
    ];

    const TYPE_TASK_MAKING = 'task_making';
    const TYPE_REVIEW_FEEDBACK = 'review_feedback';
    const TYPE_REPAIR = 'repair';


    //自动验证
    protected $_validate = [
        ['type', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['number', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['version_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['created_by', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['task_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['deadline_time', '', '', self::EXISTS_VALIDATE, 'integer'],
        ['type', ['task_making', 'review_feedback', 'repair'], '', self::EXISTS_VALIDATE, 'in'],
        ['json', '', '', self::EXISTS_VALIDATE, 'array'],
    ];

    //自动完成
    protected $_auto = [
        ['tenant_id', 'auto_fill_tenant_id', self::MODEL_INSERT, 'function'],
        ['created', 'time', self::MODEL_INSERT, 'function'],
        ['json', 'json_encode', self::EXISTS_VALIDATE, 'function'],
    ];
}
